<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CCAY-Freamwork2.0 | 登录</title>
     <link href="ccay/css/bootstrap/bootstrap.css" rel="stylesheet">
    <link href="ccay/css/fontawesome/font-awesome.css" rel="stylesheet">
    <link href="ccay/css/animate/animate.css" rel="stylesheet">
    <link href="ccay/css/inspinia/inspinia.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>
                <h1 class="logo-name">CCAY</h1>
            </div>
            <h3>欢迎登录CAY-Freamwork2.0</h3>
            <p>
            </p>
            <form id="loginForm" class="m-t" role="form" >
                <div class="form-group">
                    <input id="username" name="username" class="form-control" placeholder="用户名" required="" type="input" value="admin">
                </div>
                <div class="form-group">
                    <input type="password" name="password" class="form-control" placeholder="密码" required="">
                </div>
                <div class="form-group">
                   <select class="form-control m-b" name="CCAY_LANG">
			            <option value="zh_CN">中文</option>
			            <option value="en_US">English</option>
			        </select>
                </div>
                <input type="button" class="btn btn-primary block full-width m-b" value="登录" onclick="doLogin()">
                <a href="#"><small>忘记密码?</small></a>
                <p class="text-muted text-center"><small>还没有账号?</small></p>
                <a class="btn btn-sm btn-white btn-block" href="register.html">创建一个帐户</a>
            </form>
            <p class="m-t"> <small>Copyright</strong> CCAY-Freamwork2.0 &copy; 2017-2018</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    <script src="ccay/js/base/jquery/jquery-3.1.1.min.js"></script>
    <script src="ccay/js/base/bootstrap/bootstrap.min.js"></script>

<script type="text/javascript">
$(function(){
	 //检测用户是否已登录，
	$.get("services/security/loginService/isLogin/",
			null, 
			function(result) {
				if(result === true){
					//如果已经登录,则直接跳转到首页
					debugger;
					window.location.href=".";
				}
			},
	"json");
});
function doLogin(){
	$.post("login.html",
			$("#loginForm").serialize(), 
			function(loginVo) {
				if(loginVo.status == "success"){
					if(isInFream()){
						parent.Ccay.Component.Session.rebuiltCallback($("#username").val());
					}else{
						if(loginVo.redirectURL){
							window.location.href=loginVo.redirectURL;
						}else{
							window.location.href=".";
						}
					}
				}else{
					alert(loginVo.message);
				}
			},
	"json");
}

function isInFream(){
	return self.frameElement && self.frameElement.tagName == "IFRAME"
}
</script>

</html>